package com.cheer.service.impl;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.NumberUtil;
import com.cheer.dao.ExVotePersonDao;
import com.cheer.entity.ExVotePersonEntity;
import com.cheer.service.PersonService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * @author cheer
 */
@Service
public class PersonServiceImpl implements PersonService {

    @Autowired
    private ExVotePersonDao exVotePersonDao;

    @Override
    public void importPerson(File file) {
        int number = 1;
        List<String> files = FileUtil.listFileNames("C:\\Users\\Administrator\\Desktop\\大学习点赞照片");
        for (String png : files) {
            ExVotePersonEntity person = new ExVotePersonEntity();
            person.setActivityId(2L);
            person.setCategoryId(7L);
            person.setHeadIcon("vote2/" + png);
            person.setPersonName(StringUtils.substringBefore(png, ".png"));
            person.setPersonNumber(StringUtils.leftPad(String.valueOf(number++), 3, "0"));
            exVotePersonDao.insert(person);
        }

    }
}
